package com.example.myapplication.shortvideo.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.myapplication.R;
import com.example.myapplication.shortvideo.bean.VideoListBean;
import com.example.myapplication.shortvideo.contract.VideoContract;
import com.example.myapplication.shortvideo.view.VideoView;

import java.util.List;


public class ListVideoAdapter extends RecyclerView.Adapter<BaseVideoView> {
    private List<Object> mVideoList;
    private Context context;
    private VideoContract mContract;

    public ListVideoAdapter(Context context, List<Object> list, VideoContract contract) {
        mVideoList = list;
        this.context = context;
        mContract = contract;
    }

    @Override
    public BaseVideoView onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseVideoView view = null;
        if (viewType == 1) {//视频
            view = new VideoView(getView(R.layout.adapter_video_item, parent));
        } else if (viewType == 2) {//广告
//            view = new ADView(getView(R.layout.adapter_video_ad_details, parent));
        }
        return view;
    }


    @Override
    public void onBindViewHolder(@NonNull BaseVideoView baseVideoView, int i) {
        baseVideoView.setContent(context, mVideoList.get(i), mContract, i);
        Object object = mVideoList.get(i);
        if (object instanceof VideoListBean.DataBean.RowsBean) {
            VideoListBean.DataBean.RowsBean rowsBean = (VideoListBean.DataBean.RowsBean) object;
        } else if (!(object instanceof VideoListBean.DataBean.RowsBean)) {
        }
    }


    @Override
    public int getItemViewType(int position) {
        Object object = mVideoList.get(position);
        if (object instanceof VideoListBean.DataBean.RowsBean) {
            return 1;
        } else {
            return 2;
        }
    }


    @Override
    public int getItemCount() {
        return mVideoList.size();
    }

    private View getView(int layoutId, ViewGroup viewGroup) {
        return LayoutInflater.from(context).inflate(layoutId, viewGroup, false);
    }


}
